"""字符串类型配置

包含str类型的C++映射和方法配置
"""

# 字符串类型配置
CONFIG = {
    "str": {
        "cpp_type": "std::string",
        "includes": ["<string>"],
        "default_value": "std::string()",
        "is_type": True,
        "module": "builtins",
        "pass_by": "const_ref",  # 字符串按常量引用传递
        "satisfies_protocols": [
            "Sequence",
            "Iterable",
            "Sized",
            "Container",
            "Comparable",
            "Hashable",
        ],  # 满足的 Protocol
        "constructors": {
            "signatures": [
                "str() -> str",
                "str(x: str) -> str",
                "str(x: int) -> str",
                "str(x: float) -> str",
                "str(x: bool) -> str",
                "str(x: T) -> str",  # 泛型，通过 callback 查找 __str__ 方法
            ],
            "templates": [
                "std::string{}",
                "{x}",
                "mc::to_string({x})",
                "mc::to_string({x})",
                '({x} ? "True" : "False")',
                "",  # 空模板，通过 callback 处理
            ],
            "includes": ["mc/string.h", "mcpy/builtins.h"],
            "priority": [1, 1, 1, 1, 1, 0],  # 泛型签名优先级最低
            "callback": "mcpy.builtin.str_callback:StrFunctionCallback",
        },
        "auto_conversions": {
            "char_ptr": {"template": "{x}.c_str()", "includes": [], "priority": 1}
        },
        "methods": {
            "split": {
                "signatures": [
                    "split(self) -> list[str]",
                    "split(self, sep: str) -> list[str]",
                ],
                "templates": [
                    "mcpy::str_split({self})",
                    "mcpy::str_split({self}, {sep})",
                ],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "join": {
                "signatures": ["join(self, iterable: list[str]) -> str"],
                "templates": ["mcpy::str_join({iterable}, {self})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "replace": {
                "signatures": ["replace(self, old: str, new: str) -> str"],
                "templates": ["mc::string::replace_all({self}, {old}, {new})"],
                "includes": ["mc/string.h"],
                "priority": 1,
            },
            "strip": {
                "signatures": ["strip(self) -> str"],
                "templates": ["mc::string::trim({self})"],
                "includes": ["mc/string.h"],
                "priority": 1,
            },
            "lstrip": {
                "signatures": ["lstrip(self) -> str"],
                "templates": ["mc::string::ltrim({self})"],
                "includes": ["mc/string.h"],
                "priority": 1,
            },
            "rstrip": {
                "signatures": ["rstrip(self) -> str"],
                "templates": ["mc::string::rtrim({self})"],
                "includes": ["mc/string.h"],
                "priority": 1,
            },
            "upper": {
                "signatures": ["upper(self) -> str"],
                "templates": ["mc::string::to_upper({self})"],
                "includes": ["mc/string.h"],
                "priority": 1,
            },
            "lower": {
                "signatures": ["lower(self) -> str"],
                "templates": ["mc::string::to_lower({self})"],
                "includes": ["mc/string.h"],
                "priority": 1,
            },
            "startswith": {
                "signatures": ["startswith(self, prefix: str) -> bool"],
                "templates": ["mc::string::starts_with({self}, {prefix})"],
                "includes": ["mc/string.h"],
                "priority": 1,
            },
            "endswith": {
                "signatures": ["endswith(self, suffix: str) -> bool"],
                "templates": ["mc::string::ends_with({self}, {suffix})"],
                "includes": ["mc/string.h"],
                "priority": 1,
            },
            "find": {
                "signatures": ["find(self, sub: str) -> int"],
                "templates": ["mcpy::str_find({self}, {sub})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "count": {
                "signatures": ["count(self, sub: str) -> int"],
                "templates": ["mcpy::str_count({self}, {sub})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "__contains__": {
                "signatures": ["__contains__(self, sub: str) -> bool"],
                "templates": ["mc::string::contains({self}, {sub})"],
                "includes": ["mc/string.h"],
                "priority": 1,
            },
            "__len__": {
                "signatures": ["__len__(self) -> int"],
                "templates": ["{self}.size()"],
                "includes": [],
                "priority": 1,
            },
            "__add__": {
                "signatures": ["__add__(self, other: str) -> str"],
                "templates": ["{self} + {other}"],
                "includes": [],
                "priority": 1,
            },
            "__eq__": {
                "signatures": ["__eq__(self, other: str) -> bool"],
                "templates": ["{self} == {other}"],
                "includes": [],
                "priority": 1,
            },
            "__ne__": {
                "signatures": ["__ne__(self, other: str) -> bool"],
                "templates": ["{self} != {other}"],
                "includes": [],
                "priority": 1,
            },
            "format": {
                "signatures": ["format(self, **kwargs: dict) -> str"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
                "callback": "mcpy.builtin.str_format_callback:StrFormatCallback",
            },
            "index": {
                "signatures": ["index(self, sub: str) -> int"],
                "templates": ["mcpy::str_index({self}, {sub})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "isdigit": {
                "signatures": ["isdigit(self) -> bool"],
                "templates": ["mcpy::str_isdigit({self})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "isalpha": {
                "signatures": ["isalpha(self) -> bool"],
                "templates": ["mcpy::str_isalpha({self})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "capitalize": {
                "signatures": ["capitalize(self) -> str"],
                "templates": ["mcpy::str_capitalize({self})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "title": {
                "signatures": ["title(self) -> str"],
                "templates": ["mcpy::str_title({self})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
            "zfill": {
                "signatures": ["zfill(self, width: int) -> str"],
                "templates": ["mcpy::str_zfill({self}, {width})"],
                "includes": ["mcpy/builtins.h"],
                "priority": 1,
            },
        },
    }
}
